package com.lastproject.web.comparators;

import java.util.Comparator;

import com.lastproject.dto.UserDTO;

/**
 * compares the users depending on <br/> 
 * <ol>
 * <li>"Last Name"</li>
 * <li>"First Name"</li>
 * </ol>
 * @author davidl
 * @see Comparator
 *
 */
public class UserByNameComparator implements Comparator<UserDTO>{

	@Override
	public int compare(UserDTO user1, UserDTO user2) {
		int lastNameResult = user1.getLastname().compareToIgnoreCase(user2.getLastname());
		if (lastNameResult == 0){
			int firstNameResult = user1.getFirstname().compareToIgnoreCase(user2.getFirstname());
			return firstNameResult;
		}else{
			return lastNameResult;
		}
	}

}
